﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FluentValidation;
using RedeSocial.ViewModels.Interfaces;
using RedeSocial.ViewModels;

namespace RedeSocial.Validation
{
	/// <summary>
	/// Class responsible for validating the login view.
	/// </summary>
	public class LoginValidator : AbstractValidator<ILogin>
	{
		/// <summary>
		/// Initializes a new instance of the <see cref="LoginValidator"/> class.
		/// </summary>
		/// <param name="languageId">The language id to be use when getting the messages.</param>
		public LoginValidator(int languageId)
			: base()
		{
			RuleFor(l => l.Email).NotEmpty().When(l => string.IsNullOrEmpty(l.Email)).WithMessage(ResourceManager.GetResource(Constants.LOGINVIEW_INVALIDEMAILVALIDATION, languageId));
			RuleFor(l => l.Email).EmailAddress().When(l => !string.IsNullOrEmpty(l.Email)).WithMessage(ResourceManager.GetResource(Constants.LOGINVIEW_INVALIDEMAILVALIDATION, languageId));
			RuleFor(l => l.Password).NotEmpty().WithMessage(ResourceManager.GetResource(Constants.LOGINVIEW_INVALIDEMAILVALIDATION, languageId));
		}

	}
}
